using System;

namespace VexedLogic.X10
{
	public class HouseAndDeviceCodeUtil
	{
		public HouseAndDeviceCodeUtil()
		{
		}

		public static void GetHouseAndDeviceCode(int First, int Second, ref HouseCodes House, ref DeviceCodes Device, ref CommandCodes Command)
		{
			int first = First;
			if (first <= 112)
			{
				if (first <= 48)
				{
					if (first <= 16)
					{
						if (first == 0)
						{
							House = HouseCodes.M;
						}
						else if (first == 16)
						{
							House = HouseCodes.N;
						}
					}
					else if (first == 32)
					{
						House = HouseCodes.O;
					}
					else if (first == 48)
					{
						House = HouseCodes.P;
					}
				}
				else if (first <= 80)
				{
					if (first == 64)
					{
						House = HouseCodes.C;
					}
					else if (first == 80)
					{
						House = HouseCodes.D;
					}
				}
				else if (first == 96)
				{
					House = HouseCodes.A;
				}
				else if (first == 112)
				{
					House = HouseCodes.B;
				}
			}
			else if (first <= 176)
			{
				if (first <= 144)
				{
					switch (first)
					{
						case 127:
						{
							Command = CommandCodes.SystemInit;
							break;
						}
						case 128:
						{
							House = HouseCodes.E;
							break;
						}
						default:
						{
							if (first == 144)
							{
								House = HouseCodes.F;
								break;
							}
							else
							{
								break;
							}
						}
					}
				}
				else if (first == 160)
				{
					House = HouseCodes.G;
				}
				else if (first == 176)
				{
					House = HouseCodes.H;
				}
			}
			else if (first <= 208)
			{
				if (first == 192)
				{
					House = HouseCodes.K;
				}
				else if (first == 208)
				{
					House = HouseCodes.L;
				}
			}
			else if (first == 224)
			{
				House = HouseCodes.I;
			}
			else if (first == 240)
			{
				House = HouseCodes.J;
			}
			int second = Second;
			if (second > 72)
			{
				if (second > 112)
				{
					if (second <= 128)
					{
						if (second == 120)
						{
							Device = DeviceCodes.Eight;
							Command = CommandCodes.ChannelDown;
							return;
						}
						if (second != 128)
						{
							return;
						}
						Command = CommandCodes.AllOff;
						return;
					}
					if (second == 136)
					{
						Command = CommandCodes.VolumeUp;
						return;
					}
					if (second == 144)
					{
						Command = CommandCodes.AllOn;
						return;
					}
					if (second != 152)
					{
						return;
					}
					Command = CommandCodes.VolumeDown;
					return;
				}
				if (second <= 88)
				{
					if (second == 80)
					{
						Device = DeviceCodes.Six;
						Command = CommandCodes.ChannelUp;
						return;
					}
					if (second != 88)
					{
						return;
					}
					Device = DeviceCodes.Eight;
					Command = CommandCodes.ChannelUp;
					return;
				}
				if (second == 96)
				{
					Device = DeviceCodes.Five;
					Command = CommandCodes.ChannelDown;
					return;
				}
				if (second == 104)
				{
					Device = DeviceCodes.Seven;
					Command = CommandCodes.ChannelDown;
					return;
				}
				if (second != 112)
				{
					return;
				}
				Device = DeviceCodes.Six;
				Command = CommandCodes.ChannelDown;
				return;
			}
			if (second <= 32)
			{
				if (second <= 8)
				{
					if (second == 0)
					{
						Device = DeviceCodes.One;
						Command = CommandCodes.ChannelUp;
						return;
					}
					if (second != 8)
					{
						return;
					}
					Device = DeviceCodes.Three;
					Command = CommandCodes.ChannelUp;
					return;
				}
				if (second == 16)
				{
					Device = DeviceCodes.Two;
					Command = CommandCodes.ChannelUp;
					return;
				}
				if (second == 24)
				{
					Device = DeviceCodes.Four;
					Command = CommandCodes.ChannelUp;
					return;
				}
				if (second != 32)
				{
					return;
				}
				Device = DeviceCodes.One;
				Command = CommandCodes.ChannelDown;
				return;
			}
			if (second <= 48)
			{
				if (second == 40)
				{
					Device = DeviceCodes.Three;
					Command = CommandCodes.ChannelDown;
					return;
				}
				if (second != 48)
				{
					return;
				}
				Device = DeviceCodes.Two;
				Command = CommandCodes.ChannelDown;
				return;
			}
			if (second == 56)
			{
				Device = DeviceCodes.Four;
				Command = CommandCodes.ChannelDown;
				return;
			}
			if (second == 64)
			{
				Device = DeviceCodes.Five;
				Command = CommandCodes.ChannelUp;
				return;
			}
			if (second != 72)
			{
				return;
			}
			Device = DeviceCodes.Seven;
			Command = CommandCodes.ChannelUp;
		}
	}
}